Ext.define('HRMS.controller.user.AccountController', {
    extend: 'Ext.app.Controller',

    stores: [
         'user.Account'
    ],
   
    models:[
         'user.Account'
    ],
         
    views: [
        'user.AccountList',
        'user.AddAccount'
    ],
    
    refs: [
         {ref: 'addAccount', selector: 'addAccount', autoCreate: true, xtype: 'addaccount'}
    ],
    
    init: function() {
        this.control({
        	'accountlist #add' : {
        		click: this.onAddAccount
        	},
        	'accountlist #delete' : {
        		click: this.onDeleteAccount
        	},
        	'addaccount #submit' : {
        		click: this.onSubmitAccount
        	}
        });
    },
    
    onAddAccount: function(){
    	this.getAddAccount().show();
    },
    
    onDeleteAccount: function(){
    	alert('delete');
    },
    onSubmitAccount: function(button){
    	var win    = button.up('window'),
        	form   = win.down('form'),
        	record = form.getRecord(),
        	values = form.getValues();
    
    
    		if (values.id > 0){
    			record.set(values);
    		} else{
    			record = Ext.create('HRMS.model.user.Account');
    			record.set(values);
    			record.setId(0);
    			this.getUserAccountStore().add(record);
    		}
    
    		win.close();
    		this.getUserAccountStore().sync();    	
    }
});
